﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using DevExpress.XtraEditors;
using Lamex.Library;
using Lamex.Interface;
using Lamex.Library.CommonClass;
using System.Diagnostics;
using Lamex.Main;

namespace Lamex.mMES.UI
{
    public partial class frmMES_Main : frmModuleBase
    {
        private const int APPCOMMAND_VOLUME_MUTE = 0x80000;
        private const int APPCOMMAND_VOLUME_UP = 0xA0000;
        private const int APPCOMMAND_VOLUME_DOWN = 0x90000;
        private const int WM_APPCOMMAND = 0x319;
        [DllImport("user32.dll")]
        public static extern IntPtr SendMessageW(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);

        public frmMES_Main()
        {
            InitializeComponent();
            menuStrip1.Text = ModuleNames.mMES; //与AssemblyModuleEntry.ModuleName定义相同
        }
        public override MenuStrip GetModuleMenu()
        {
            return this.menuStrip1;
        }

        private void menuMES_ServiceMonitor_Click(object sender, EventArgs e)
        {
            //MdiTools.OpenChildForm(this.MdiParent as IMdiForm, typeof(frmMES_Test02), sender as ToolStripMenuItem);
        }

        private void menuMES_DataExchange_Click(object sender, EventArgs e)
        {
            MessageBox.Show("待开发......","提示消息");
        }

        private void menuMES_PushService_Click(object sender, EventArgs e)
        {
            MessageBox.Show("待开发......", "提示消息");
        }

        private void menuMES_DatabaseList_Click(object sender, EventArgs e)
        {
            //ProcessStartInfo MyStarInfo = new ProcessStartInfo();
            //MyStarInfo.FileName = @"\\tx-fs10\tx-fs1\IMA\MES\System\SystemSource\DatabaseTableViewList.xlsx";
            ////窗口起始状态最大化
            //MyStarInfo.WindowStyle = ProcessWindowStyle.Maximized;
            //Process MyProcees = new Process();
            //MyProcees.StartInfo = MyStarInfo;
            //MyProcees.Start();
            MdiTools.OpenChildWebBrowse(this.MdiParent as IMdiForm, new frmBaseChildWinForm("Sys_DataAuthority", 0, true, true), sender as ToolStripMenuItem);
        }

        private void menuMES_TableViewList_Click(object sender, EventArgs e)
        {
            MdiTools.OpenChildForm(this.MdiParent as IMdiForm, typeof(frmMES_TableViewList), sender as ToolStripMenuItem);
          
            //ProcessStartInfo MyStarInfo = new ProcessStartInfo();
            //MyStarInfo.FileName = @"\\tx-fs10\tx-fs1\IMA\MES\System\SystemSource\DatabaseTableViewList.xlsx";
            ////窗口起始状态最大化
            //MyStarInfo.WindowStyle = ProcessWindowStyle.Maximized;
            //Process MyProcees = new Process();
            //MyProcees.StartInfo = MyStarInfo;
            //MyProcees.Start();
        }

        private void menuMES_TeamviewList_Click(object sender, EventArgs e)
        {
            //ProcessStartInfo MyStarInfo = new ProcessStartInfo();
            //MyStarInfo.FileName = @"\\tx-fs10\tx-fs1\IMA\MES\System\SystemSource\TeamViewerList.xlsx";
            ////窗口起始状态最大化
            //MyStarInfo.WindowStyle = ProcessWindowStyle.Maximized;
            //Process MyProcees = new Process();
            //MyProcees.StartInfo = MyStarInfo;
            //MyProcees.Start();

            MessageBox.Show("待开发......", "提示消息");
        }

        private void menuMES_About_Click(object sender, EventArgs e)
        {
            frmMain_About frm = new frmMain_About();
            frm.ShowDialog();
        }

        private void menuMES_ProjectData_Click(object sender, EventArgs e)
        {
            MdiTools.OpenChildWebBrowse(this.MdiParent as IMdiForm, new frmBaseChildWinForm("MAPPLYINFO", 0, false, true), sender as ToolStripMenuItem);
        }

        private void menuMES_NCTransfer_Click(object sender, EventArgs e)
        {
            MdiTools.OpenChildWebBrowse(this.MdiParent as IMdiForm, new frmBaseChildWinForm("DPT_Report_NC", 0, true, true), sender as ToolStripMenuItem);
        }

        private void menuMES_DevelopRecord_Click(object sender, EventArgs e)
        {
            MdiTools.OpenChildWebBrowse(this.MdiParent as IMdiForm, new frmBaseChildWinForm("Sys_Version_Manage", 0, true, true), sender as ToolStripMenuItem);
        }

        private void menuMES_IE_Engineering_Click(object sender, EventArgs e)
        {
            MdiTools.OpenChildWebBrowse(this.MdiParent as IMdiForm, new frmBaseChildWinForm("DPT_Report_IE", 0, true, true), sender as ToolStripMenuItem);
        }

        private void menuMES_Process_Improve_Click(object sender, EventArgs e)
        {
            MdiTools.OpenChildWebBrowse(this.MdiParent as IMdiForm, new frmBaseChildWinForm("DPT_Daily_Improve", 0, true, true), sender as ToolStripMenuItem);
        }

        private void menuMES_Overall_Click(object sender, EventArgs e)
        {
            //SendMessageW(this.Handle, WM_APPCOMMAND, this.Handle, (IntPtr)APPCOMMAND_VOLUME_MUTE);
            MdiTools.OpenChildForm(this.MdiParent as IMdiForm, typeof(frmMES_Layout_Lamex), sender as ToolStripMenuItem);
        }

        private void menuMES_Laminate_Click(object sender, EventArgs e)
        {
            MessageBox.Show("开发中......");
            //SendMessageW(this.Handle, WM_APPCOMMAND, this.Handle, (IntPtr)APPCOMMAND_VOLUME_MUTE);
            //MdiTools.OpenChildForm(this.MdiParent as IMdiForm, typeof(frmMES_Layout_Laminate), sender as ToolStripMenuItem);
        }

        private void menuMES_Panel_Click(object sender, EventArgs e)
        {
            //SendMessageW(this.Handle, WM_APPCOMMAND, this.Handle, (IntPtr)APPCOMMAND_VOLUME_MUTE);
            MdiTools.OpenChildForm(this.MdiParent as IMdiForm, typeof(frmMES_Layout_Panel),sender as ToolStripMenuItem);
        }

        private void menuMES_Seating_Click(object sender, EventArgs e)
        {
            //SendMessageW(this.Handle, WM_APPCOMMAND, this.Handle, (IntPtr)APPCOMMAND_VOLUME_MUTE);
            MdiTools.OpenChildForm(this.MdiParent as IMdiForm, typeof(frmMES_Layout_Seating), sender as ToolStripMenuItem);
        }

        private void menuMES_MCG_Click(object sender, EventArgs e)
        {
            MessageBox.Show("开发中......");
            //SendMessageW(this.Handle, WM_APPCOMMAND, this.Handle, (IntPtr)APPCOMMAND_VOLUME_MUTE);
            //MdiTools.OpenChildForm(this.MdiParent as IMdiForm, typeof(frmMES_Layout_MCG), sender as ToolStripMenuItem);
        }

        private void menuMES_RGB_Click(object sender, EventArgs e)
        {
            MdiTools.OpenChildWebBrowse(this.MdiParent as IMdiForm, new frmBaseChildWinForm("MES_Layout_Block_Color", 0, true, true), sender as ToolStripMenuItem);
        }

        private void menuMES_IE_Maintain_Authority_Click(object sender, EventArgs e)
        {
            MdiTools.OpenChildWebBrowse(this.MdiParent as IMdiForm, new frmBaseChildWinForm("IE_Prod_Type_Ctrl", 0, true, true), sender as ToolStripMenuItem);
        }

        private void menuMES_Data_Modified_Record_Click(object sender, EventArgs e)
        {
            MdiTools.OpenChildWebBrowse(this.MdiParent as IMdiForm, new frmBaseChildWinForm("sys_Data_Modified_Record", 0, false, false), sender as ToolStripMenuItem);
        }

        private void menuMES_Data_Synchronization_Click(object sender, EventArgs e)
        {
            MdiTools.OpenChildForm(this.MdiParent as IMdiForm, typeof(FrmMES_Synchronization), sender as ToolStripMenuItem);
        }

        private void menuMES_App_Data_Maintance_Click(object sender, EventArgs e)
        {
            MdiTools.OpenChildWebBrowse(this.MdiParent as IMdiForm, new frmBaseChildWinForm("DPT_App_Management", 0, true, true), sender as ToolStripMenuItem);
        }

        private void menuMES_App_Operation_Guide_Click(object sender, EventArgs e)
        {
            MdiTools.OpenChildForm(this.MdiParent as IMdiForm, typeof(frmMES_AppManage), sender as ToolStripMenuItem);
        }

        private void menuMES_Operation_Config_Click(object sender, EventArgs e)
        {
            MdiTools.OpenChildWebBrowse(this.MdiParent as IMdiForm, new frmBaseChildWinForm("OP_Operation_Function", 0, true, true), sender as ToolStripMenuItem);
        }

        private void menuMES_WorkfLow_IE_Click(object sender, EventArgs e)
        {
            MdiTools.OpenChildForm(this.MdiParent as IMdiForm, typeof(frmMES_Workflow_IE), sender as ToolStripMenuItem);
        }

        private void menuMES_WorkfLow_Draft_Click(object sender, EventArgs e)
        {
            MdiTools.OpenChildForm(this.MdiParent as IMdiForm, typeof(frmMES_Workflow_Draft), sender as ToolStripMenuItem);
        }

        private void menuMES_OP_onTarget_Click(object sender, EventArgs e)
        {
            MdiTools.OpenChildForm(this.MdiParent as IMdiForm, typeof(frmMES_Operation_KPI), sender as ToolStripMenuItem);          
        }

        private void menuMES_OP_onSite_Click(object sender, EventArgs e)
        {
            MdiTools.OpenChildForm(this.MdiParent as IMdiForm, typeof(frmMES_Operation_Workshop_Overview), sender as ToolStripMenuItem);
        }

        private void menuMES_OP_System_Click(object sender, EventArgs e)
        {
            MdiTools.OpenChildForm(this.MdiParent as IMdiForm, typeof(frmMES_Operation_Management), sender as ToolStripMenuItem);
        }

        private void menuMES_Lab_TreeList_Click(object sender, EventArgs e)
        {
            MdiTools.OpenChildForm(this.MdiParent as IMdiForm, typeof(frmMES_Lab_TreeList), sender as ToolStripMenuItem);
        }

        private void menuMES_Lab_TreeMap_Click(object sender, EventArgs e)
        {
            MdiTools.OpenChildForm(this.MdiParent as IMdiForm, typeof(frmMES_Lab_TreeMap), sender as ToolStripMenuItem);
        }

        private void menuMES_Lab_Timeline_Click(object sender, EventArgs e)
        {
            MdiTools.OpenChildForm(this.MdiParent as IMdiForm, typeof(frmMES_Lab_TimeLine), sender as ToolStripMenuItem);
        }

        private void menuMES_Project_Application_Click(object sender, EventArgs e)
        {
            string strWebPath = @"http://172.23.134.36:8090/Login.aspx";
            //打开网页
            //非嵌入式
            //MdiTools.OpenIE(strWebPath);
            //嵌入式，框架窗体
            //MdiTools.OpenChildWebBrowse(this.MdiParent as IMdiForm, new frmWebForm(strWebPath, "项目申请"), sender as ToolStripMenuItem);
            //嵌入式，本地窗体
            MdiTools.OpenChildForm(this.MdiParent as IMdiForm, typeof(frmMES_Project_Application), sender as ToolStripMenuItem);
        }

        private void menuMES_Testing_Record_Click(object sender, EventArgs e)
        {
            MdiTools.OpenChildForm(this.MdiParent as IMdiForm, typeof(frmMES_Testing_Management), sender as ToolStripMenuItem);
        }

        private void menuMES_Project_Summerize_Click(object sender, EventArgs e)
        {
            MdiTools.OpenChildForm(this.MdiParent as IMdiForm, typeof(frmMES_Project_Summarize), sender as ToolStripMenuItem);
        }

        private void menuMES_3Tec_MES_Click(object sender, EventArgs e)
        {
            string strAppPath = @"D:\3TEC\bin";
            //非嵌入式
            //WinForm原生
            //System.Diagnostics.Process process = new System.Diagnostics.Process();
            //process.StartInfo.FileName = strAppPath + @"\3Tec MES.exe";
            ////Application.StartupPath;//这里一定要设置为exe的所在目录，因为要调用其配置文件
            //process.StartInfo.WorkingDirectory = strAppPath;
            //process.StartInfo.Arguments = strAppPath;
            //process.Start();
            //process.WaitForExit();

            //不带参
            //MdiTools.OpenIE(@"C:\Windows\System32\notepad.exe");
            //带配置参数(启动路径）
            //MdiTools.OpenIE(strAppPath + @"\3Tec MES.exe;" + strAppPath);

            //嵌入式
            //不带参
            //MdiTools.OpenChildWebBrowse(this.MdiParent as IMdiForm, new frmExeForm(@"C:\Windows\System32\notepad.exe", "记事本"), sender as ToolStripMenuItem);
            //带参
            //MdiTools.OpenChildWebBrowse(this.MdiParent as IMdiForm, new frmExeForm(strAppPath + @"\3Tec MES.exe;" + strAppPath + ";" + strAppPath, "3Tec MES"), sender as ToolStripMenuItem);
            //MdiTools.OpenChildWebBrowse(this.MdiParent as IMdiForm, new frmExeForm(
            //                            @"M:\MES\ShareFolder\李钟哇\3TEC_New_Version\bin\3Tec MES.exe;
            //                            M:\MES\ShareFolder\李钟哇\3TEC_New_Version\bin;
            //                            M:\MES\ShareFolder\李钟哇\3TEC_New_Version\bin", 
            //                            "MES"), sender as ToolStripMenuItem);
            MdiTools.OpenChildWebBrowse(this.MdiParent as IMdiForm, new frmExeForm(
                            @"\\Tx-fs10\tx-fs1\LAMEX\MES\3Tec_MES\bin\3Tec MES.exe;
                                        \\Tx-fs10\tx-fs1\LAMEX\MES\3Tec_MES\bin;
                                        \\Tx-fs10\tx-fs1\LAMEX\MES\3Tec_MES\bin",
                            "MES"), sender as ToolStripMenuItem);
        }

        private void menuMES_3Tec_Dashboard_Click(object sender, EventArgs e)
        {
            MdiTools.OpenChildWebBrowse(this.MdiParent as IMdiForm, new frmWebForm(@"http://172.23.134.46/ProductionData/DashboardView.aspx", "3Tec Dashboard"), sender as ToolStripMenuItem);
        }

        private void menuMES_Lab_Schedule_Click(object sender, EventArgs e)
        {
            MdiTools.OpenChildForm(this.MdiParent as IMdiForm, typeof(frmMES_Lab_Schedule), sender as ToolStripMenuItem);
        }

        private void menuMES_Project_Schedule_Click(object sender, EventArgs e)
        {
            MdiTools.OpenChildForm(this.MdiParent as IMdiForm, typeof(frmMES_Project_Schedule), sender as ToolStripMenuItem);
        }

        private void menuMES_Project_Progress_Click(object sender, EventArgs e)
        {
            MdiTools.OpenChildForm(this.MdiParent as IMdiForm, typeof(frmMES_Project_Progress), sender as ToolStripMenuItem);         
        }

        private void menuMES_Lab_Digital_Calendar_Click(object sender, EventArgs e)
        {
            MdiTools.OpenChildForm(this.MdiParent as IMdiForm, typeof(frmMES_Lab_Digital_Calendar), sender as ToolStripMenuItem);
        }

        private void menuMES_Operation_Calendar_Click(object sender, EventArgs e)
        {
            MdiTools.OpenChildForm(this.MdiParent as IMdiForm, typeof(frmMES_Operation_Digital_Calendar), sender as ToolStripMenuItem);
        }

        private void menuMES_Lab_DEV_Express_Click(object sender, EventArgs e)
        {
            Lamex.Common.IniFile ini = new Lamex.Common.IniFile(Application.StartupPath + "\\config\\CSFramework3.ini");
            int iLanguage = int.Parse(ini.IniReadValue("Configuration", "ChangeLanguage").ToString());
            if (iLanguage == 0)
                Help.ShowHelp(this, @"D:\Zbk_Ref\DevExpress\WindowsFormsChmHelp.v18.1.4\Devexpress Winform中文文档.CHM");
            else
            //网络盘无法显示内容，WINDOWS安全机制问题
            //Help.ShowHelp(this, @"\\Tx-fs10\tx-fs1\LAMEX\MES\AppMgmt\Help\WindowsFormsCHMHelp.v17.1.5\WindowsForms.chm");
            Help.ShowHelp(this, @"D:\Zbk_Ref\DevExpress\WindowsFormsChmHelp.v18.1.4\WindowsForms.chm");
        }

        private void menuMES_Operation_Function_Demo_Click(object sender, EventArgs e)
        {
            MdiTools.OpenChildForm(this.MdiParent as IMdiForm, typeof(frmMES_Operation_Function_Demo), sender as ToolStripMenuItem);
        }

        private void menuMES_User_Feedback_Click(object sender, EventArgs e)
        {
            MdiTools.OpenChildForm(this.MdiParent as IMdiForm, typeof(frmMES_Testing_Management), sender as ToolStripMenuItem);
        }

        private void menuMES_Workshop_Layout_Click(object sender, EventArgs e)
        {
            MdiTools.OpenChildForm(this.MdiParent as IMdiForm, typeof(frmMES_Layout_Operation), sender as ToolStripMenuItem);
        }

        private void menuMES_App_Commonly_Used_Click(object sender, EventArgs e)
        {
            MdiTools.OpenChildForm(this.MdiParent as IMdiForm, typeof(frmMES_App_Commonly_Used), sender as ToolStripMenuItem);
        }

        private void menuMES_Lab_Testing_Click(object sender, EventArgs e)
        {
            //MdiTools.OpenChildWebBrowse(this.MdiParent as IMdiForm, new frmBaseChildWinForm("Transfer_101_Inside_record", 0, false, false), sender as ToolStripMenuItem);
            MdiTools.OpenChildForm(this.MdiParent as IMdiForm, typeof(frmMES_TestManage), sender as ToolStripMenuItem);
        }

        private void menuMES_Lab_ChartControl_Click(object sender, EventArgs e)
        {
            MdiTools.OpenChildForm(this.MdiParent as IMdiForm, typeof(frmMES_Lab_ChartControl), sender as ToolStripMenuItem);
        }
        private void menuMES_Project_Log_Record_Click(object sender, EventArgs e)
        {
            //string CurUser = Lamex.Common.Loginer.CurrentUser.Account;
            //switch (CurUser)
            //{
            //    case "Rocky He":
            //        MdiTools.OpenChildForm(this.MdiParent as IMdiForm, typeof(frmMES_Project_Log_Add), sender as ToolStripMenuItem);
            //        break;
            //    default:
            //        MdiTools.OpenChildWebBrowse(this.MdiParent as IMdiForm, new frmBaseChildWinForm("DPT_Project_Dev_Log", 0, true, false), sender as ToolStripMenuItem);
            //        break;
            //}

            MdiTools.OpenChildForm(this.MdiParent as IMdiForm, typeof(frmMES_Project_Log_Add), sender as ToolStripMenuItem);

        }

        private void menuMES_Project_Item_List_Click(object sender, EventArgs e)
        {
            MdiTools.OpenChildWebBrowse(this.MdiParent as IMdiForm, new frmBaseChildWinForm("DPT_Project_Item_List", 0, true, false), sender as ToolStripMenuItem);
        }

        private void menuMES_Project_Dev_TimeLine_Click(object sender, EventArgs e)
        {
            MdiTools.OpenChildForm(this.MdiParent as IMdiForm, typeof(frmMES_Project_Log_Timeline), sender as ToolStripMenuItem);
        }

        private void menuMES_Lab_WEB_Frame_Click(object sender, EventArgs e)
        {
            MdiTools.OpenChildWebBrowse(this.MdiParent as IMdiForm, new frmWebForm(@"http://172.23.137.185:9599/Home/Login", "美时MES WEB系统"), sender as ToolStripMenuItem);
        }

        private void menuMES_Lab_Image_Recognition_Click(object sender, EventArgs e)
        {
            MdiTools.OpenChildForm(this.MdiParent as IMdiForm, typeof(frmMES_Lab_Image_Recognition), sender as ToolStripMenuItem);
        }

        private void menuMES_Lab_Master_Detail_Table_Click(object sender, EventArgs e)
        {
            MdiTools.OpenChildForm(this.MdiParent as IMdiForm, typeof(frmMES_Lab_Master_Detail_Table), sender as ToolStripMenuItem);
        }

        private void menuMES_Lab_Menu_Snipping_Click(object sender, EventArgs e)
        {
            MdiTools.OpenChildForm(this.MdiParent as IMdiForm, typeof(frmMES_Lab_Blank), sender as ToolStripMenuItem);
        }

        private void menuMES_System_Menu_Structure_Click(object sender, EventArgs e)
        {
            MdiTools.OpenChildForm(this.MdiParent as IMdiForm, typeof(frmMES_System_Menu_Structure), sender as ToolStripMenuItem);
        }

        private void menuMES_Lab_Devl_Controls_Click(object sender, EventArgs e)
        {
            MdiTools.OpenChildForm(this.MdiParent as IMdiForm, typeof(frmMES_Lab_Controls), sender as ToolStripMenuItem);
        }

        private void menuMES_WorkfLow_Kanban_Click(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 同步数据库表数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        //private void menuMES_Data_Synchronization_Click(object sender, EventArgs e)
        //{

        //}

        //private void menuMES_TestMGT_Click(object sender, EventArgs e)
        //{
        //    MdiTools.OpenChildForm(this.MdiParent as IMdiForm, typeof(FrmMES_TestMGT), sender as ToolStripMenuItem);
        //}

    }
}